<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <form name="f1">
      <p>
        <input type="text" name="age" />
      </p>
    </form>
    <script>
      document.f1.age.onfocus = function () {
        console.log("onfocus", "获取焦点");
      };
      document.f1.age.onblur = function () {
        console.log("onblur", "失去焦点");
      };

      setTimeout(() => {
        document.f1.age.focus();
      }, 3000);

      setTimeout(() => {
        document.f1.age.blur();
      }, 5000);
    </script>
  </body>
</html>
